home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group94a.txt
/
000183_icon-group-sender _Tue Jun 21 11:27:52 1994.msg
< prev
next >
Wrap
Internet Message Format
|
1994-08-19
|
2KB
Received: by cheltenham.cs.arizona.edu; Tue, 21 Jun 1994 06:40:56 MST
Message-Id: <m0qG32b-000BzQC@bootes.cus.cam.ac.uk>
X-Sender: jdg1002@pop.cus.cam.ac.uk
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Date: Tue, 21 Jun 1994 11:27:52 +0100
To: icon-group@cs.arizona.edu
From: Jason Grossman <Jason.Grossman@ucs.cam.ac.uk>
Subject: Re: anti-ugly contest
Status: R
Errors-To: icon-group-errors@cs.arizona.edu
>Help stamp out ugly icon code!
>
>I'm getting better. My first ugly version of the following routine,
>produced after much trial and error, required two (count 'em!) extra
>variables. After some inspection, I managed to reduce it to:
>
> procedure squeeze(s)
> # Squeze out excess blanks from inside a string
> s2 := ""
> s ? {
> while s2 ||:= tab(upto(" ")+1) do tab(many(" "))
> s2 ||:= tab(0)
> }
> return s2
> end
>
>That cut the number of extra variables down to one (s2).
>Question: Is there an even more elegant way to do this that requires
>no extra variables?
I do it using a replace procedure, so I could say
procedure squeeze (s)
s := replace (" ", "", s)
end
and replace is defined by
procedure replace (a, b, s)
/s := \&subject # in case we're doing pattern matching
while (s [find (a, s)+:*a] := b)
return s
end
Is this inefficient? (Be lenient. I'm a beginner.)
Jason